﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using INHollandair.Core.Models;
using INHollandair.Core.Services;

namespace INHollandair.Shop
{
    public partial class ShowProduct : System.Web.UI.Page
    {
        private Product selectedProduct = new Product();
        private readonly ProductService _svc = new ProductService();

        protected void Page_Load(object sender, EventArgs e)
        {
            String QueryID = Request.QueryString.Get("id");
            int validatedID;
            if (int.TryParse(QueryID, out validatedID))
            {
                //Set MultiView
                MultiViewShowProduct.SetActiveView(validData);

                //Get product data from database
                Product product = _svc.GetProductById(validatedID);
                selectedProduct = product;

                //Set labels
                ProductImage.ImageUrl = product.Image;
                ProductName.Text = product.Name;
                ProductDate.Text = product.Date.ToString("dd-MM-yyyy");
                ProductPrice.Text = product.Price.ToString() + " INHollandair Miles";
                ProductDescription.Text = product.Description;
            }
            else
            {
                //Set MultiView
                MultiViewShowProduct.SetActiveView(invalidData);
            }

        }

        protected void orderproduct_Click(object sender, EventArgs e)
        {
            //Set product in the session
            Session["selectedProduct"] = selectedProduct;

            //Redirect user to order page
            Response.Redirect("~/Shop/OrderProduct.aspx");
        }
    }
}